import { defineStore } from "pinia";
import storageManger from "@/utils/StorageManger";

export interface Token {
	access_token: string;
	id_token: string;
	expires_in: number;
	refresh_token: string;
	scope: string;
	token_type: string;
}

/**
 * @description: 用户信息store
 */
export const useUserInfoStore = defineStore("userInfoStore", {
	state: () => ({
		token:
			storageManger.get<Token>("token", sessionStorage) ||
			({
				access_token: "",
				id_token: "",
				expires_in: 0,
				refresh_token: "",
				scope: "",
				token_type: "",
			} as Token),
	}),
	persist: {
		enabled: true,
		strategies: [
			{
				storage: sessionStorage,
				paths: ["token"],
			},
		],
	},
});
